
if ( typeof Skt.Util === 'undefined' )
	Skt.Util = {};

Skt.Util.addNotification = function(message, okCallbackText, cancelCallbackText) {
	$("#users-sidebar-messages").append(Skt.Util.buildNotificationHtml(message, okCallbackText, cancelCallbackText));
};

Skt.Util.buildNotificationHtml = function(message, okCallbackText, cancelCallbackText) {
	var id = 'notification-' + new ObjectId().toString();
	var html = "";
	
	html += '<div class="alert alert-info usersidebar-alert" id="' + id + '">'; 
		html += '<span class="usersidebar-alert-message">' + message + '</span>';
		html += '<div class="btn-group btn-group-sm">';
			html += '<button class="btn-success btn-sm" type="button"';
			if ( okCallbackText )
				html += ' onclick="' + okCallbackText + '; $(\'#' + id + '\').remove();"';
			else
				html += ' onclick="$(\'#' + id + '\').remove();"';
			html += '>Ok</button>' ;
			if ( cancelCallbackText ) {
				html += '<button class="btn-primary btn-sm" type="button"';
				html += ' onclick="' + cancelCallbackText + '; $(\'#' + id + '\').remove();"';
				html += '>Cancel</button>' ;
			}
		html += '</div>';
	html += '</div>';
	
	return html;
};

Skt.Util.updateEmptyMessage = function(sketchpad) {
	if ( sketchpad.getEditor().getCurrentCanvas() == null ) {
		$("#start-message").html("Select a or create slide to view");
		$("#start-message").show();
		$("#editor").hide();
	} else {
		$("#start-message").hide();
		$("#editor").show();
	}
	
};

Skt.Util.postGroupCreation = function(sketchpad, name, type) {
	$.post( 
			sketchpad.getBasePath() + "/app/newGroup", 
			{
				activityId: sketchpad.getActivity().id,
				name: name,
				type: type
			}, 
			function(response) {
				sketchpad.getGroupsManager().addGroup(Number(response.id), response.name, response.type, Number(response.author.id));
			}
		);
};

Skt.Util.postRoomCreation = function(sketchpad, type, groupId) {
	$.post( 
		sketchpad.getBasePath() + "/app/newSlide", 
		{
			activity_id: sketchpad.getActivity().id,
			type: type,
			group_id: groupId
		}, 
		function(response) {
			groupId = null;
			if ( response.group != null )
				groupId = response.group.id; 
			
			sketchpad.addRoom(Number(response.id), response.type, response.author, groupId, null);
		}
	);
};